package cn.edu.scau.cmi.lixiaoyuan.client;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;


import cn.edu.scau.cmi.lixiaoyuan.composite.consistent.ConsistentOrganization;
import cn.edu.scau.cmi.lixiaoyuan.composite.consistent.Person;
import cn.edu.scau.cmi.lixiaoyuan.composite.consistent.Team;


public class ConsistentCompositeClient {
	public static ConsistentOrganization trank = new Team("根目录");

	
	public static void createTeam(String name) {
		ConsistentOrganization team = new Team(name);
		trank.addChild(team);
		
	}
	public static void addToTeam(String name,ConsistentOrganization obj) {
		ConsistentOrganization person = new Person(name);
		obj.addChild(person);
		
	}
	
	public static ConsistentOrganization findTeam(String name) {
       for(Object obj :trank.children) {
    	   int judge = 0;
			if((((ConsistentOrganization)obj).getName()).equals(name)) {
				return (ConsistentOrganization) obj;
			}
		}
	return null;
		
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		System.out.println("1.输入组，2.添加组员，其他键输出");
		int judge = sc.nextInt();
		
		
		while(judge==1||judge==2) {
			if(judge==1) {
				System.out.print("请输入组名:");
				
				String name1 = sc.next();
				createTeam(name1);
			}else if(judge == 2){
				System.out.print("请输入组名:");
				
				String name1 = sc.next();
				
				if(findTeam(name1)==null) {
					System.out.println("不存在该队伍");
				}else {
					System.out.print("输入组员名字：");
					String name2 = sc.next();
					
					addToTeam(name2, findTeam(name1));
				}
			}
			
			System.out.println("1.输入组，2.添加组员，其他键输出");
			judge = sc.nextInt();
		}
	    sc.close();
		trank.doSomething();
		
//		System.out.println("输入一个组多少个人");
//		ConsistentOrganization team = new Team();
//	    int num = sc.nextInt();
//	    for(int i=0;i<num;i++) {
//	    	System.out.println("输入成员名字：");
//	    	ConsistentOrganization person = new Person();
//	    	String tname = sc.next();
//	    	person.setName(tname);
//	    	team.addChild(person);
//	    }
//	    System.out.println("输入组的名字：");
//	    String tname = sc.next();
//	    team.setName(tname);
//	    team.doSomething();
	   
//		ConsistentOrganization trunk=new Team();
//		((Team)trunk).setName("树干");
//		
//
//		ConsistentOrganization firstBranch=new Team();
//		((Team)firstBranch).setName("第一个树枝");
//		
//		
//		ConsistentOrganization secondBranch=new Team();
//		((Team)secondBranch).setName("第二个树枝");
//		
//		
//		
//		
//		ConsistentOrganization firstLeaf=new Person();
//		((Person)firstLeaf).setName("第一个树枝上的第一片树叶");
//		
//		ConsistentOrganization secondLeaf=new Person();
//		((Person)secondLeaf).setName("第一个树枝上的第二片树叶");
//		
//		
//		ConsistentOrganization thirdLeaf=new Person();
//		((Person)thirdLeaf).setName("第二个树枝上的第一片树叶");
//		
//		ConsistentOrganization forthLeaf=new Person();
//		((Person)forthLeaf).setName("第二个树枝上的第二片树叶");
//		
////		语法没问题。
//		firstLeaf.addChild(secondLeaf);
//		
//		firstBranch.addChild(firstLeaf);
//		firstBranch.addChild(secondLeaf);
//		secondBranch.addChild(thirdLeaf);
//		secondBranch.addChild(forthLeaf);
//		
//		trunk.addChild(firstBranch);
//		trunk.addChild(secondBranch);
////		TODO 请同学们后面在作业中自己补充。
//		trunk.setKongge(2);
//		 trunk.doSomething();
		
		
		
		 
	
	
	   
	}
       
       
}
